Ext.namespace("CMS");
var TEMP_NUM = 1;
var empty_select = ['' , '---请选择---'];
var pub_add_option = 1 , pub_edit_option = 2 , pub_del_option = 4;
var pubOptionSelectData = [empty_select , [pub_add_option , '新增'] , [pub_edit_option , '修改']];
function show2(title,text) {
    Ext.Msg.alert(title,text);
}
function show3(title,text,val) {
    show2(title,text);
    return val;
}
function getTempNum() {var tmp = TEMP_NUM; TEMP_NUM += 1; return tmp;}
function showTip(title,text) {Ext.example.msg(title , text , 2);return false;}
function showTip2(title,text,t) {Ext.example.msg(title , text , t);return false;}
var MAIN_CONSOLE = "console_manager";
var defLabelPad = 9 , defLabelPad2 = 0;
var pubfields = ['data','label'];
var pubonly = ['label'];
var pubTempates = {cell: new Ext.Template(
   '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} x-selectable {css}" style="{style}" tabIndex="0" {cellAttr}>',
   '<div class="x-grid3-cell-inner x-grid3-col-{id}" {attr}>{value}</div>', '</td>')};
if(Ext.isChrome) {
     var chromeDatePickerCSS = ".x-date-picker {border-color: #1b376c;background-color:#fff;position: relative;width: 185px;}";
     Ext.util.CSS.createStyleSheet(chromeDatePickerCSS,'chromeDatePickerStyle');
}else if(Ext.isIE) {
    defLabelPad = 11;
    defLabelPad2 = 2;
}
function getGridView(text) {return new Ext.grid.GridView({emptyText:text , templates:pubTempates})}
function getGroupView(text) {return new Ext.grid.GroupingView({forceFit:true,markDirty: false,templates:pubTempates,emptyText:text})}
function formatComment(comment) {return "<pre>" + (comment == null ? '' : comment) + "</pre>";}
function filerString(string) {return Ext.util.Format.trim(string);}
function isStrEmpty(string) {return Ext.isEmpty(filerString(string));}
function isObjEmpty(obj) {return isStrEmpty(obj.getValue())}
function checkObjs(objs,params) {
    for(var i in objs) {
        var obj = objs[i];
        if(obj.isFormField) {
	        if(!obj.allowBlank && !obj.allowNull && isStrEmpty(obj.getValue())) {showN(obj.fieldLabel); return false;}
	        if(obj.getValue()) {
	        	if(obj.format) params[obj.name] = getTime(obj);
	        	else params[obj.name] = obj.getValue();
	        }
        }
    }
    return params;
}
function getTime(obj) {if(obj.getValue()) {return obj.getValue().getTime()} return null;}
function showN(name) {showTip('提示','输入项：[' + name + '] 不能为空。');return false;}
function getRadio(name,v,label,checked) {return {xtype:"radio",boxLabel:label,name:name,inputValue:v,labelSeparator:'',checked:checked}}
function getRadio2(name,v,label) {return getRadio(name,v,label,false)}
function ajaxSuc(resp,fn,param,win) {
    var respText = Ext.util.JSON.decode(resp.responseText);
    showTip2('提示' , respText['msg'] , 2);
    if(respText.status == '1') {
        if(fn) {if(param) fn.call(this , param);else fn.call(this);}
        if(win) win.close();
    }else {
    	if(win) win.enable();
    }
}
function ajaxFail(resp,opts) {alert(resp.responseText)}
function convertText(srcString) {
    if(srcString == null) return '';
    var text = replaceAll(srcString,'&#039;',"'");
    text = replaceAll(text,'&gt;',">");
    text = replaceAll(text,'&lt;',"<");
    text = replaceAll(text,'&#034;',"\"");
    return text;
}
function createNormalComStore(data) {return new Ext.data.SimpleStore({fields:pubfields,data:data,id:0});}
function createNormalComStore2(data) {return new Ext.data.SimpleStore({fields:pubonly,data:data,id:0});}
function getTemStore(data,fields) {var ds = new Ext.data.Store({
    proxy: new Ext.data.MemoryProxy(data), reader: new Ext.data.ArrayReader({id: 0},fields)
});ds.load();return ds;
}
function getTempCheckProxy(storeProp,storeProp2,width,array,name1,name2,title,fn,searchFields) {
    var objArr1 = converArr(array , false , null , true);
    var objArr2 = converArr(array , false , null , true);
    storeProp.fields = objArr1.fields;
    storeProp2.fields = objArr2.fields;
    var ds1 = new Ext.data.JsonStore(storeProp);
    var ds2 = new Ext.data.JsonStore(storeProp2);
    var tbars = null;
    if(searchFields) {
        tbars = ['-'];
        forEach(searchFields , function(row) {
            tbars.push({
                text:row.fieldLabel
            },'-',row,'-');
            row.on('specialkey' , function(field, event) {
                if(event.keyCode != 13) return;
                refreshForm();
            });
        });
        tbars.push(new Ext.Button({text:'查询',iconCls:'searchIcon2',handler:function() {
            refreshForm();
        }}) , '-');
    }
    var from = new Ext.grid.GridPanel({
        title:name1 , region:'west',width:width ,columns:objArr1.columns,ds:ds1,sm:objArr1.columns[0],
        listeners:{'rowdblclick' : function(thiz,row,e) {convertValue(from,toPanel)}},
        tbar:tbars
    });
    var toPanel =  new Ext.grid.GridPanel({
        title:name2 , region:'east',width:width ,columns:objArr1.columns,ds:ds2,sm:objArr2.columns[0],
        listeners:{'rowdblclick' : function(thiz,row,e) {convertValue(toPanel,from)}}
    });
    var refreshForm = function() {
        var params = {};
        forEach(searchFields , function(row) {
            params[row['name']] = row.getValue();
        });
        from.getStore().load({params:params});
    };
    var change1 = new Ext.Button({iconCls:'rightIcon',name:'chang1'});
    var change2 = new Ext.Button({iconCls:'leftIcon',name:'chang2'});
    var centerP = new Ext.form.FormPanel({region:'center',width:50,labelAlign:"center",
        layout:'table',layoutConfig:{columns:1},frame:true,defaults:{xtype:'panel',height:50},
        items:[{html:'&nbsp;'},{html:'<br/>',items:[change1]},{html:'',items:[change2]}]
    });
    var win = new Ext.Window({
        title:title,height:520,width:(2 * width + 50),layout:'border',buttonAlign:'center',
        items:[from , centerP, toPanel],buttons:[{
           text:'确 定',handler:function() {fn.call(this)}
        },{text:'关 闭',handler:function() {win.close();}}]
    });
    win.show();
    var convertValue = function(from,toP) {
        var rowObj = from.getSelectionModel().getSelected();
        from.getStore().remove(rowObj);
        toP.getStore().add(rowObj);
    };
    var convertValues = function(from,toP) {
        var lines = from.getSelectionModel().getSelections();
        for(var i = 0 ,size = lines.length ; i < size ; i++) {
            from.getStore().remove(lines[i]);
            toP.getStore().add(lines[i]);
        }
    };
    var clickBack = function(obj) {
        if(obj.name == 'chang1') {
            convertValues(from,toPanel);
        }else {
            convertValues(toPanel,from);
        }
    };
    registClick([change1 , change2] , clickBack);
    return {'ds1':ds1,'ds2':ds2 , 'win':win};
}
function getTempCheck(data1,data2,width,array,name1,name2,title,fn) {
    var objArr1 = converArr(array , false , null , true);
    var objArr2 = converArr(array , false , null , true);
    var ds1 = getTemStore(data1 , objArr1.fields);
    var ds2 = getTemStore(data2 , objArr2.fields);
    var mod1 = new Ext.grid.ColumnModel(objArr1.columns);
    var mod2 = new Ext.grid.ColumnModel(objArr2.columns);
    var from = new Ext.grid.GridPanel({
        title:name1 , region:'west',width:width ,cm:mod1,ds:ds1,sm:objArr1.columns[0],plugins:checkColumn,
        listeners:{'rowdblclick' : function(thiz,row,e) {convertValue(from,toPanel)}}
    });
    var toPanel =  new Ext.grid.GridPanel({
        title:name2 , region:'east',width:width ,cm:mod2,ds:ds2,sm:objArr2.columns[0],
        listeners:{'rowdblclick' : function(thiz,row,e) {convertValue(toPanel,from)}}
    });
    var change1 = new Ext.Button({iconCls:'rightIcon',name:'chang1'});
    var change2 = new Ext.Button({iconCls:'leftIcon',name:'chang2'});
    var centerP = new Ext.form.FormPanel({region:'center',width:50,labelAlign:"center",
        layout:'table',layoutConfig:{columns:1},frame:true,defaults:{xtype:'panel',height:50},
        items:[{html:'&nbsp;'},{html:'<br/>',items:[change1]},{html:'',items:[change2]}]
    });
    var win = new Ext.Window({
        title:title,height:300,width:(2 * width + 50),layout:'border',
        items:[from , centerP, toPanel],buttons:[{
           text:'确 定',handler:function() {fn.call(this)}
        },{text:'关 闭',handler:function() {win.close();}}]
    });
    win.show();
    var convertValue = function(from,toP) {
        var rowObj = from.getSelectionModel().getSelected();
        from.getStore().remove(rowObj);
        toP.getStore().add(rowObj);
    };
    var convertValues = function(from,toP) {
        var lines = from.getSelectionModel().getSelections();
        for(var i = 0 ,size = lines.length ; i < size ; i++) {
            from.getStore().remove(lines[i]);
            toP.getStore().add(lines[i]);
        }
    };
    var clickBack = function(obj) {
        if(obj.name == 'chang1') {
            convertValues(from,toPanel);
        }else {
            convertValues(toPanel,from);
        }
    };
    registClick([change1 , change2] , clickBack);
    return {'ds1':ds1,'ds2':ds2 , 'win':win};
}
function registClick(array,fn) {
    for(var i = 0 , size = array.length ; i < size ; i++) {
        array[i].on('click',function(thiz) {
            fn.call(this,thiz);
        });
    }
}
function createNormlCommon(width,data,fieldLabel,value,editable,name) {
    return createNormlCommon2(width,createNormalComStore(data),fieldLabel,value,editable,name,'data');
}
function createNormlCommon3(width,data,fieldLabel,value,editable,name) {
    return createNormlCommon2(width,createNormalComStore2(data),fieldLabel,value,editable,name,'label');
}
function createNormlCommon2(width,store,fieldLabel,value,editable,name,valueField) {
    return new Ext.form.ComboBox({
        width:width,height:22,store:store,valueField:valueField,
        displayField:'label',editable:editable,triggerAction:'all',emptyText:'请选择...',
        mode:'local',value:value,fieldLabel:fieldLabel,name:name
    });
}
function createNormlCommon4(width,store,fieldLabel,value,editable,name,valueField,nullable) {
    return new Ext.form.ComboBox({
        width:width,height:22,store:store,valueField:valueField,
        displayField:'label',editable:editable,triggerAction:'all',emptyText:'请选择...',
        mode:'local',value:value,fieldLabel:fieldLabel,name:name,allowBlank:nullable
    });
}
function createLocalCommonStore(data) {return new Ext.data.SimpleStore({fields:pubfields,data:data,id:0});}
function createLocalCommon(prop) {
	var commonProp = {//store、width
    height:22,valueField:'data',displayField:'label',editable:true,triggerAction:'all',mode:'local',value:''
  };
  copyMap(prop , commonProp);
  return new Ext.form.ComboBox(commonProp);
}
function createLocalCommonByData(prop , data) {
	prop['store'] = createLocalCommonStore(data);
	return createLocalCommon(prop);
}
function createProxyComm(props) {
    var template = {//fieldLabel|width|name and so on
        typeAhead: true,mode: 'local',value:'',
        forceSelection: true,triggerAction: 'all',
        selectOnFocus: true,displayField: 'label',
        valueField:'data',width: 200,iconCls: 'no-icon',editable:false,
        getListParent: function() {
            return this.el.up('.x-menu');
        }
    };
    copyMap(props , template);
    return new Ext.form.ComboBox(template);
}
function createProxyComm2(props,storeProps) {
    var temp = {
        autoDestroy: true,id: 'id',
        fields:[{name:'data',type:'string'},{name:'label',type:'string'}],
        autoLoad: true
    };
    if(storeProps) copyMap(storeProps,temp);
    props['store'] = new Ext.data.JsonStore(temp);
    return createProxyComm(props);
}
function regiestSpecialKey(fn , items) {
    for(var i = 0 , size = items.length ; i < size ; i++) {
        items[i].on("specialkey", function(field, event) {
            if(event.keyCode != 13) return;
            fn.call(this);
        });
    }
}
function regiestSelect(fn , items) {
    for(var i = 0 , size = items.length ; i < size ; i++) {
        items[i].on("select", function() {fn.call(this);});
    }
}
function regiestOther(fn , items ,event) {
    for(var i = 0 , size = items.length ; i < size ; i++) {
        items[i].on(event, function(thiz,e) {fn.call(this,thiz);});
    }
}
function closeAndActive(consoleId , closeP , activeP) {
    var console = Ext.getCmp(consoleId);
    if(closeP != null && console.getEl(closeP) != null) {
        console.remove(closeP);
    }
    if(activeP != null && console.getEl(activeP) != null) {
        console.setActiveTab(activeP);
    }else {
        console.setActiveTab(0);
    }
}
function isEmpty(v) {
    return (v == undefined || v == '' || v == null);
}
function forEach(array , fn) {
    if(!array) return;
    for(var i = 0 , size = array.length ; i < size ; i++) {
        fn.call(this , array[i] , i);
    }
}
function forEachDs(ds, fn) {
    for(var i = 0 , size = ds.data.length ; i < size ; i++) {
        fn.call(this , ds.getAt(i).data , i);
    }
}
function getJson(v) {return Ext.util.JSON.decode(v)}
function confirm(msg,fn) {Ext.MessageBox.confirm('提示',msg ,fn)}
function converArr(array,isRowNum,expander,isCheckBox) {
    var columns = [];
    var fields = [];
    var pos = 0 , colIndex = 0 ,fieldIndex = 0;

    if(isRowNum) {
        columns[0] = new Ext.grid.RowNumberer();pos = 1;
    }else if(isCheckBox) {
        columns[0] = new Ext.grid.CheckboxSelectionModel();pos = 1;
    }
    if(expander) {columns[pos] = expander;pos += 1;}
    for(var i = 0 ,size = array.length ; i < size ; i++) {
        var obj = array[i];
        if(obj['display'] == null || !obj['display']) {
             fields[i] = {name:obj['name']};
            if(obj['type'] != undefined && obj['type'] != '')
                fields[i]['type'] = obj['type'];
        }
        if(obj['hidden'] == null || !obj['hidden']) {
            var nowIndex = colIndex + pos;
            columns[nowIndex] = {header:obj['header'],width:obj['width'],dataIndex:obj['name']};
            if(!isEmpty(obj['sortable'])) {columns[nowIndex]['sortable'] = obj['sortable'];}
            if(!isEmpty(obj['renderer'])) {columns[nowIndex]['renderer'] = obj['renderer'];}
            if(!isEmpty(obj['editor'])) {columns[nowIndex]['editor'] = obj['editor'];}
            colIndex++;
        }
    }
    return {columns:columns,fields:fields};
}
function getField(prop) {return new Ext.form.TextField(prop);}
function getArea(prop) {return new Ext.form.TextArea(prop)}
function getNumber(prop) {return new Ext.form.NumberField(prop)}
function getCheckBox(prop) {return new Ext.form.Checkbox(prop)}
function getLabel(txt) {return new Ext.Panel({html:txt , style:'margin-top:' + defLabelPad + 'px;font-size:13px;color:red;'});}
function getLabel2(txt,top) {return new Ext.Panel({html:txt , style:'margin-top:'+(top * defLabelPad)+'px;font-size:13px;color:red;'});}
function getLabel4(txt,top) {return new Ext.Panel({html:txt , style:'margin-top:'+(top)+'px;font-size:13px;color:red;',border:false});}
function getLablel3(url,f, txt) {
    return new Ext.Panel({html:'<a href="'+url+'">'+txt+'</a>',fieldLabel:f , isFormField:false});
}
function getFormField(field , text , title , padd) {
    var paddNow = (padd) ? padd : 5;
    return new Ext.Panel({
       xtype:'panel',layout:"column",labelWidth:150,isFormField:true,fieldLabel:title,border:false,
       defaults:{columnWidth:.4,layout:"form",hideLabels:true,bodyStyle:"padding:2px"},
       items:[field,{columnWidth : .6,layout : 'form',border:false,items:[getLabel4(text,paddNow)]}]
    });
}
function getFormField2(field , text , padd , extendItem , mast , width) {
    var paddNow = (padd) ? padd : 5;
    var item = (extendItem) ? extendItem : getLabel4(text,paddNow ,mast);
    var columnWidth = (600 / width) * .15;
    var lastWidth = 1 - columnWidth;
    var innerPanel = {columnWidth : columnWidth,layout : 'form',border:false , buttonAlign:'left' , height:field.height};
    if(extendItem) {
       if(extendItem.type == 'button') {
           innerPanel['buttons'] = [extendItem];
       }else {
           innerPanel['items'] = [extendItem];
       }
    }else {
       innerPanel['items'] = getLabel4(text , paddNow , mast);
    }
    return new Ext.Panel({
       xtype:'panel',layout:"column",labelWidth:150,isFormField:true,fieldLabel:field.fieldLabel,border:false,
       defaults:{columnWidth:lastWidth,layout:"form",hideLabels:true,bodyStyle:"padding:2px"},width:width,
       items:[field,innerPanel],
       setValue:function(v) {
    	   field.setValue(v);
       },
       getValue:function(v) {
    	   return field.getValue();
       }
    });
}
function getBt(txt) {return '<span style="color:red;font:bold 13px tahoma,arial,helvetica,sans-serif;">'+txt+'</span>'}
function creDate(prop) {prop['format'] = 'Y-m-d'; return new Ext.form.DateField(prop)}
function getHidden(prop) {return new Ext.form.Hidden(prop)}
function getRowModel() {return new Ext.grid.RowSelectionModel({singleSelect:true})}
function getProxy(url) {return new Ext.data.HttpProxy({url:url})}
function ajax(prop,panel) {
	if(panel) panel.disable();
	Ext.Ajax.request(prop);
}
function getPageDs(url,id,objArr) {
    return new Ext.data.JsonStore({
        proxy:getProxy(url),
        root:'rows',
        totalProperty : 'total',
        successProperty : 'success',
        idProperty:id,
        autoLoad:false,
        fields: objArr.fields
    });
}
function getGroupDs(url,id,objArr,group,order) {
    if(!order) order = "ASC";
    return new Ext.data.GroupingStore({
        reader: new Ext.data.JsonReader({
            root:'rows',
            totalProperty : 'total',
            successProperty : 'success',
            idProperty:id,
            autoLoad:false,
            fields:objArr.fields
        }),
        proxy:getProxy(url),
        groupOnSort:true,
        sortInfo:{field: group, direction: order}
    });
}
function getPageBBar(pageSize,ds) {
    return new Ext.PagingToolbar({
         pageSize:pageSize,
         store:ds,
         displayInfo : true,
         displayMsg : '当前第 {0} - {1} 条记录 / 一共 {2} 条',
         emptyMsg : "没有记录",
         plugins:[new Ext.ui.plugins.SliderPageSize(), new Ext.ui.plugins.ComboPageSize({ addToItem: false, prefixText: '每页', postfixText: '条'})]
         //plugins: new Ext.ux.SlidingPager()
    });
}
function getEmptyForm() {
    return getMyEmptyForm([getArea({fieldLabel:'备注' ,name:'desc', width:300 , height:100})]);
}
function getMyEmptyForm(items,lbWidth) {
    if(!lbWidth) lbWidth = 150;
    return new Ext.FormPanel({
        bodyStyle:'padding:5px',deferredRender:false,defaultType: 'textfield',region:'center',
        items: items,labelWidth:lbWidth,autoScroll:true
    });
}
function getMyEmptyForm2(items,title) {
    return new Ext.FormPanel({
        bodyStyle:'padding:5px',deferredRender:false,defaultType: 'textfield',region:'center',
        items: items,title:title,frame:true,labelWidth:150,autoScroll:true
    });
}
function getEmptyPanel(buttons , title , panel) {
    return getEmptyPanel2(buttons , title , panel , 205);
}
function getEmptyPanel2(buttons , title , panel , height) {
    return getEmptyPanel3(buttons , title , panel , height , 450);
}
function getEmptyPanel3(buttons , title , panel , height , width , parentPanel) {
    return getEmptyPanel4(buttons , title , panel , height , width , null , true , parentPanel);
}
function getEmptyPanel4(buttons , title , panel , height , width , tbars , isShow , parentPanel) {
    var prop = {
        title:title,height:height,width:width,resizable:true,maximizable:true,
        layout:'border',buttonAlign:'center',autoScroll:true,
        items:[panel],
        buttons:buttons
    };
    if(tbars) prop['tbar'] = tbars;
    var win = new Ext.Window(prop);
    win.addButton({
        text:'关闭',handler:function() {win.close()}
    });
    win.show();
    if(parentPanel) {
    	parentPanel.disable();
    	win.on('beforedestroy' , function() {
    		parentPanel.enable();
    	});
    }
    return win;
}
CMS.Window = Ext.extend(Ext.Window , {
    resizable:true,maximizable:true,height:500,width:800,
    layout:'border',buttonAlign:'center',autoScroll:true,
    initComponent:function() {
        var panelObj = this;
        this.buttons = this.buttons ? this.buttons : [];
        this.buttons.push({
            text:'关闭',handler:function() {panelObj.close()}
        });
        if(this.parentPanel) {
            this.parentPanel.disable();
            this.on('beforedestroy' , function() {this.parentPanel.enable()})
        }
        CMS.Window.superclass.initComponent.call(this);
        if(!this['hideWin']) this.show();
    }
});
function copyMap(from,to) {
    if(from) {for(var prop in from) {to[prop] = from[prop]}}
    return to;
}
function getTab(props) {
    var temp = {
        activeTab:0,resizeTabs:true,deferredRender:false,minTabWidth: 140,tabWidth:140,enableTabScroll:true,
        defaults: { autoScroll:true }
    };
    return copyMap(props , temp);
}
function getGrid(title,objArr,props,oprops) {
    return new Ext.grid.GridPanel(getGridProp(title,objArr,props,oprops));
}
function getGridProp(title,objArr,props,oprops) {
    props.fields = objArr.fields;
    var gridProp = {
        store:new Ext.data.JsonStore(props),columns:objArr.columns,title:title,
        sm:getRowModel(),autoScroll:true,viewConfig:getGridView('没有数据....')
    };
    copyMap(oprops , gridProp);
    return gridProp;
}
function replaceAll(srcString,before,after) {
    var dstStr = "",i = 0,size = srcString.length,firstChar = before.charAt(0),beSize = before.length;
    while(i < size) {
        var now = srcString.charAt(i);
        if(firstChar = now && (before == srcString.substring(i,i + beSize))) {
            dstStr += after;
            i += beSize;
        }else {
            dstStr += now;
            i++;
        }
    }
    return dstStr;
}
function convertText2(srcString , pre) {
    if(srcString == null) return '';
    var text = replaceAll(srcString,"'","&#039;");
    text = replaceAll(text,">","&gt;");
    text = replaceAll(text,"<","&lt;");
    text = replaceAll(text,"\"","&#034;");
    if(pre) text = replaceAll(text,"\n","<br/>");
    return text;
}
function getSpan(title,value,pre) {
    return '<span style="font-size:13px;font-weight: bold;">' + title + '</span>：<span style="font-size:13px;">'
            + (pre && value ? convertText2(value , true) : convertText2(value)) + '</span><br/>';
}
function getWW(title,nick) {
    return '<span style="font-size:13px;font-weight: bold;">' + title + '</span>：<span class="J_WangWang" data-nick="'
            + nick + '">' + nick + '</span><br/>';
}
function pubDeleteRow(grid , altKey , altTitle , ajaxUrl , ds, fn) {
	var row = grid.getSelectionModel().getSelected().data;
	confirm('确定要删除' + altTitle + '：【' + row[altKey] + "】吗？", function(v) {
		if(v == 'yes') {
			if(!ajaxUrl) {
				ds.remove(grid.getSelectionModel().getSelected());
				showTip2('提示' , altTitle + '信息已经删除成功！' , 3);
				if(fn) fn.call(this);
			}else {
				ajax({
	    			url:ajaxUrl,
	    			params:{id:grid.getSelectionModel().getSelected().id , type:pub_del_option},
		    		success:function(resp) {ajaxSuc(resp , fn);}
	    		});
			}
		}
	});
}
function pubEditRow(type , items , grid , altTitle ,height , width , ajaxUrl, fn ,parentWin) {
	var option = (type == pub_add_option) ? "新增" : "修改";
	var realItems = [] , index = 0;
	if(type == 2) {
    	var row = grid.getSelectionModel().getSelected().data;
    	forEach(items , function(item) {
    		if(!item.notEdit) {
    			if(item.store && item.store.url) {
    				item.store.on('load' , function() {item.setValue(row[item.name])});
    			}else {
    				item.setValue(row[item.name]);
    			}
    			realItems[index++] = item;
    		}
    	});
    	items = realItems;
    }
    var form = getMyEmptyForm(items);
    var win = getEmptyPanel3([{
    	text:'确定' , handler:function() {
    		if(!ajaxUrl) {
    			showTip2('提示' , altTitle + '信息' + option + '成功！' , 3);
    			win.close();
    			if(fn) fn.call(this);
    			return;
    		}
    		var params = checkObjs(items , {type:type});
    		if(!params) return;
    		ajax({
    			url:ajaxUrl,
    			params:params,
	    		success:function(resp) {
	    			ajaxSuc(resp , fn , null , win);
	    		}
    		});
    	}
    }] , option + altTitle + '信息' , form , height , width , parentWin);
}
function getStr(str) {if(str) return str; return "";}
function registPageDsParams(ds , items , fn) {
	ds.on("beforeload",function(thiz,options) {
		forEach(items , function(item) {
			if(item.format) thiz.baseParams[item.name] = getTime(item);
			else thiz.baseParams[item.name] = item.getValue();
		});
	});
	forEach(items , function(item) {
		if(item.store || item.format) {
			item.on('select' , function() {
				fn.call(this);
			});
		}else {
			item.on('specialkey' , function(field, event) {
				if(event.keyCode != 13) return;
            	fn.call(this);
			});
		}
	});
}
//params为k-v结构
function downloadFile2(baseUrl , params) {
	if(baseUrl.indexOf("?") != -1) baseUrl += "&" + Ext.urlEncode(params);
	else baseUrl += "?" + Ext.urlEncode(params);
	downloadFle(baseUrl);
}
function downloadFile(url) {
	var iframeEle = document.createElement("iframe");
	iframeEle.src = url;
	iframeEle.style.display = "none";
    document.body.appendChild(iframeEle);
}
function getFrameHtml(url) {
	return '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="' + url + '"></iframe>';
}
function getFrameHtml2(url,id) {
	return '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="' + url + '" id="' + id + '"></iframe>';
}
CMS.PubListContent = function(title,config_list,baseId,prop) {
	var content_id = baseId + getTempNum();
	var defaultProps = {
        title:title,region:'center',html:'<div id="' + content_id + '"></div>',
        autoScroll:true
    };
    if(prop) copyMap(prop , defaultProps);
	CMS.PubListContent.superclass.constructor.call(this, defaultProps);
    this.setContent = function(node) {
    	var htmlCode = '<table style="table-layout:fixed;word-break: break-all;word-wrap:break-word;" width="100%"><tbody><tr><td class="plat_table_detail">名称</td><td class="plat_table_detail">内容</td></tr>';
    	var index = 1;
        forEach(config_list , function(config) {
            if(config['comp'] && config['vl']) {
                if(node[config['comp']] != config['vl']) return;
            }
            var classNode = getTabDetailRowCss(index++);
            var name = config['name'];
            var value = node[name];
            if(config['func']) {
                value = config['func'].call(this , value);
            }
            if(config['pre']) {
            	value = '<pre>' + value + '</pre>';
            }
            var cname = config['cname'];
            htmlCode += '<tr><td class="' + classNode[0] + '">' + cname + ' : <td class="' + classNode[1] + '">' + value + '</td></tr>';
        });
        Ext.get(content_id).dom.innerHTML = htmlCode + '</tbody></table>';
    };
};
Ext.extend(CMS.PubListContent, Ext.Panel);

CMS.ConsoleManager = function(title) {
    var welcome = new CMS.WelcomePanel(title);
    CMS.ConsoleManager.superclass.constructor.call(this, {
        id:'console_manager',
        region:'center',
        activeTab:0,
        //tabPosition:'bottom',
        resizeTabs:true,
        deferredRender:false,
        minTabWidth: 140,
        tabWidth:140,
        enableTabScroll:true,
        defaults: {
            autoScroll:true
        },
        items:[welcome]
    });

};
Ext.extend(CMS.ConsoleManager, Ext.TabPanel);
CMS.WelcomePanel = function(title) {
    var htmlCode = "<fieldset style='font-size: 12px;height: 430'><img id ='img1' src='share/images/工程和设计变更流程图.png' height='100%'/></fieldset><fieldset style='font-size: 12px;height: 240'><img id ='img1' src='share/images/客户变更流程图.png' height='100%'/></fieldset>";
	//注释
    CMS.WelcomePanel.superclass.constructor.call(this, {
        title:'Home',
        border:false,frame:true,
        scripts:true,autoScroll:true,
        discardUrl:true,
        nocache:true,
        timeout:9000,
        scope:this,
        html:htmlCode
    });
};
Ext.extend(CMS.WelcomePanel, Ext.Panel);